package com.flx.noodle.websocket.service;

import com.flx.noodle.websocket.dao.UserDao;
import com.flx.noodle.websocket.entity.SSOUser;
import com.flx.noodle.websocket.searcher.UserSearcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fenglixiong on 2017/10/2.
 */
@Service
public class UserService {

	@Autowired
	private UserDao userDao;

	public SSOUser getUserById(int id) {
		return userDao.getUserById(id);
	}

	public SSOUser getUserByName(String name) {
		return userDao.getUserByName(name);
	}

	public int saveOrUpdateUser(SSOUser ssoUser) {
		if (ssoUser.getUserId() == null) {
			return insertUser(ssoUser);
		} else {
			return updateUser(ssoUser);
		}
	}

	public int insertUser(SSOUser ssoUser) {
		return userDao.insertUser(ssoUser);
	}

	public int updateUser(SSOUser ssoUser) {
		return userDao.updateUser(ssoUser);
	}

	public int deleteUser(int id) {
		return userDao.deleteUser(id);
	}

	public List<SSOUser> findUserList(UserSearcher searcher) {
		return userDao.findUserList(searcher);
	}

	public SSOUser getUserBySessionId(String sessionId) {
		return userDao.getUserBySessionId(sessionId);
	}

	public int updateSessionId(int userId, String sessionId) {
		return userDao.updateUserSessionId(userId, sessionId);
	}

}
